<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>告警短信发送策略</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"> 
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<jsp:include page="../resource.jsp"></jsp:include>
	<style type="text/css">
	    #authority table, caption, tbody, tfoot, thead, tr, th, td{
	        vertical-align: middle;
	    }
	</style>
	<script type="text/javascript">
	$(document).ready(function() {
		var h = '85%';
 		if($.browser.msie && $.browser.version == 8.0){
 	    	 h = $(self.parent.parent.frames['mainFrame']).height()-87; 
 	    }
        $("#messageStrategy").omGrid({
        	dataSource : 'messageStrategy!findAll.do',
            height : h,
            limit : 20,
            showIndex : true,
            colModel : [ 
                         {header : '告警等级', name : 'alarmLevel', width : 90, align : 'center'},
                         {header : '告警类别', name : 'alarmTypeId', width : 100, align : 'center',renderer:function(value){
                             if(value == '1') {
                            	 return '软件告警';
                             }else if(value == '2') {
                            	 return '硬件告警';
                             }else{
                            	 return '通信告警';
                             }
                         }},
                         {header : '告警次数', name : 'alarmTimes', width : 90, align : 'center'},
                         {header : '通知方式', name : 'sendType', width : 100, align : 'center',renderer:function(value){
                             if(value == '1') {
                            	 return '短信';
                             }else if(value == '2') {
                            	 return '邮件';
                             }else{
                            	 return '短信/邮件';
                             }
                         }},
                         {header : '重发次数', name : 'resendTimes', width : 90, align : 'center'}, 
                         {header : '重发间隔(分钟)', name : 'resendInterval', width : 120, align : 'center'} ]
        });
        
        $("#messageStrategyEditor").omDialog({
        	autoOpen: false,
  		    height: 300,
  		    width : 480,
  		    buttons: [{
                text : "确定", 
                click : function () {
                  $("#messageStrategyForm").submit();
                }
             }, {
                text : "取消", 
                click : function () {
                  $("#messageStrategyEditor" ).omDialog("close");
              }
          }]
        });
        
        
        $("#messageStrategyAdd").click(function(){
        	$("#messageStrategyForm").resetForm();
        	$("#messageStrategyId").val('');
        	$("#alarmLevel").val('');
        	$("#alarmTypeId").val('0');
        	$("#alarmTimes").val('');
        	$("#sendType").val('9');
        	$("#resendTimes").val('');
        	$("#resendInterval").val('');
        	$("#messageStrategyEditor").omDialog("open");
        });
        
        $("#messageStrategyDelete").click(function(){
        	var selects = $("#messageStrategy").omGrid("getSelections",true);
        	if(selects.length <= 0){
        		$.omMessageBox.alert({content:'请您选择删除记录'});
        		return;
        	}
        	 $.omMessageBox.confirm({
                 title:'确认删除',
                 content:'您确定删除该数据？',
                 onClose:function(result){
                	 if(result){
                		 $.ajax({
                			 url : 'messageStrategy!delete.do',
                			 data : {deleteId:selects[0].id},
                			 success : function(data){
                				 if(data == '1'){
                					 $.omMessageTip.show({timeout : 2000,content : '删除成功！'});
                					 $("#messageStrategy").omGrid("reload");
                				 }else{
                					 $.omMessageTip.show({timeout : 2000,content : '删除失败！'});
                				 }
                			 }
                		 });
                	 }
                 }
             });

        	
        });
        
        $("#messageStrategyModify").click(function(){
        	var selects = $("#messageStrategy").omGrid("getSelections",true);
        	if(selects.length <= 0){
        		$.omMessageBox.alert({content:'请您选择修改记录'});
        		return;
        	}
        	$.ajax({
  			  url: "messageStrategy!findByID.do",
  			  data : {strategyId : selects[0].id},
  			  dataType : 'json',
  			  success: function(data){
  	        	$("#messageStrategyForm").resetForm();
  	        	$("#messageStrategyId").val(data[0].id);
  	        	$("#alarmLevel").val(data[0].alarmLevel);
  	        	$("#alarmTypeId").val(data[0].alarmTypeId);
  	        	$("#alarmTimes").val(data[0].alarmTimes);
  	        	$("#sendType").val(data[0].sendType);
  	        	$("#resendTimes").val(data[0].resendTimes);
  	        	$("#resendInterval").val(data[0].resendInterval);
  			  }
  			});
        	$("#messageStrategyEditor").omDialog("open");
        });
        
        var alarmOptions  = {
      		  url : 'messageStrategy!save.do',
                success : function(data){
                   	if(data != '0'){  
                       	$.omMessageTip.show({timeout : 2000,content : '保存成功！'});
                       	$("#messageStrategyEditor").omDialog('close');
                       	$("#messageStrategy").omGrid("reload");
                   	}else{
                   		$.omMessageTip.show({timeout : 2000,content : '保存失败！',type : 'error'});
                   	}
                }
      	  };
      	  $("#messageStrategyForm").submit(function() {
                $(this).omAjaxSubmit(alarmOptions);
                return false;//返回false,阻止浏览器默认行为
          });
    });
	</script>  
  </head>
  
  <body>
    <div class="toolbar mar">
		         <a href="#" class="rbutton" id="messageStrategyAdd"><span><img src="../images/add.gif" width="14" height="14" /><ins>添加</ins></span></a>
		         <a  class="line"></A>
		         <a href="#" class="rbutton" id="messageStrategyModify"><span><img src="../images/edit.gif" width="14" height="14" /><ins>修改</ins></span></a>
		         <a  class="line"></A>
		         <a href="#" class="rbutton" id="messageStrategyDelete"><span><img src="../images/del.gif" width="14" height="14" /><ins>删除</ins></span></a>
	</div>
    <table id="messageStrategy"></table>
    
    <div id="messageStrategyEditor" title="编辑内容" style="display: none;">
     <form id="messageStrategyForm" method="post">
          <table width="100%" border="0" class="grid_layout" cellspacing="0">
             <tr>
               <td width="10%" align="right">告警等级：</td>
               <td width="28%" colspan="3" align="left">
                 <input type="hidden" id="messageStrategyId" name="strategy.id">
                 <select name="strategy.alarmLevel" id="alarmLevel">
                 	<option value="0">全部</option>
                 	<option value="1">1</option>
                 	<option value="2">2</option>
                 	<option value="3">3</option>
                 	<option value="4">4</option>
                 	<option value="5">5</option>
                 </select>
               </td>
             </tr>
             <tr>
               <td width="10%" align="right">告警类别：</td>
               <td width="28%" colspan="3" align="left">
                   <select name="strategy.alarmTypeId" id="alarmTypeId">
                 	<option value="0">全部</option>
                 	<option value="1">软件告警</option>
                 	<option value="2">硬件告警</option>
                 	<option value="9">通信告警</option>
                 </select>
               </td>
               </td>
             </tr>
             <tr>
               <td width="10%" align="right">告警次数：</td>
               <td width="28%" colspan="3" align="left">
                  <input type="text" id="alarmTimes" name="strategy.alarmTimes" class="input_text" />
               </td>
             </tr>
             <tr>
               <td width="10%" align="right">通知方式：</td>
               <td width="28%" colspan="3" align="left">
                 <select name="strategy.sendType" id="sendType">
                 	<option value="9">全部</option>
                 	<option value="1">短信</option>
                 	<option value="2">邮件</option>
                 </select>
               </td>
             </tr>
             <tr>
               <td width="10%" align="right">重发次数：</td>
               <td width="28%" colspan="3" align="left">
                  <input type="text" id="resendTimes" name="strategy.resendTimes" class="input_text" />
               </td>
             </tr>
             <tr>
               <td width="10%" align="right">重发间隔(分钟)：</td>
               <td width="28%" colspan="3" align="left">
                  <input type="text" id="resendInterval" name="strategy.resendInterval" class="input_text" />
               </td>
             </tr>
           </table>
         </form>
   </div>
  </body>
</html>
